<template>
  <view class="landing-page">
    <!-- 背景纹理图片 - 铺满整个页面 -->
    <view class="page-bg">
      <image src="/static/bg.jpg" mode="aspectFill"></image>
    </view>

    <!-- 顶部标题 -->
    <view class="page-header">
      <text class="header-subtitle">好友为您推荐优质产品</text>
      <text class="header-title">左慈太和枕</text>
    </view>

    <!-- 红包卡片 -->
    <view class="coupon-card">
      <view class="coupon-badge">
        <text class="badge-icon">✨</text>
        <text class="badge-text">限时优惠</text>
        <text class="badge-dot">·</text>
        <text class="badge-text">新人专享</text>
      </view>
      <view class="coupon-amount">
        <text class="amount-number">20元</text>
        <text class="amount-label">红包</text>
      </view>
    </view>

    <!-- 领取按钮 - 添加动效吸引用户点击 -->
    <view class="claim-button-wrapper">
      <button class="claim-button" @click="openCouponDetail">
        <text class="button-text">立即领取并使用</text>
        <text class="button-icon">🎁</text>
      </button>
      <!-- 呼吸光晕效果 -->
      <view class="button-glow"></view>
    </view>

    <!-- 视频轮播区域 -->
    <view class="video-section">
      <view class="video-tip">
        <text class="tip-icon">📺</text>
        <text class="tip-text">点击观看产品介绍视频</text>
        <text class="tip-sub">（将跳转到视频号观看）</text>
      </view>

      <view class="video-swiper-container">
        <swiper
          class="video-swiper"
          :indicator-dots="true"
          :autoplay="true"
          :interval="3000"
          :duration="500"
          :circular="true"
          indicator-color="rgba(255, 255, 255, 0.5)"
          indicator-active-color="#4a7c59"
        >
          <swiper-item v-for="(video, index) in videoList" :key="index">
            <view class="video-item">
              <channel-video
                class="product-video"
                :feed-token="video.token"
                :autoplay="false"
                :loop="true"
                object-fit="contain"
                @error="onVideoError"
              ></channel-video>
            </view>
          </swiper-item>
        </swiper>
      </view>
    </view>

    <!-- 产品信息 -->
    <view class="product-info">
      <text class="product-name">【睡个好觉】草本安神</text>
      <text class="product-desc">好友推荐，给您带来前所未有的深度睡眠体验</text>
      <view class="product-features">
        <view class="feature-tag">草本配方</view>
        <view class="feature-tag">涵养内气</view>
        <view class="feature-tag">健康睡眠</view>
      </view>
    </view>

    <!-- 养生理念 -->
    <view class="philosophy-section">
      <view class="philosophy-icon">
        <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
          <circle cx="20" cy="20" r="20" fill="#4a7c59"/>
          <path d="M20 10c-2 0-4 2-4 4 0 2 1 3 2 4 1 1 2 2 2 4s-1 3-2 4c-1 1-2 2-2 4 0 2 2 4 4 4s4-2 4-4c0-2-1-3-2-4-1-1-2-2-2-4s1-3 2-4c1-1 2-2 2-4 0-2-2-4-4-4z" fill="white"/>
        </svg>
      </view>
      <text class="philosophy-title">传承千年养生智慧</text>
      <text class="philosophy-text">精选优质草本材料，为您提供自然的睡眠体验。身心修养的奥秘，尽在天然草本的温柔呵护中。</text>
      <view class="philosophy-tags">
        <text class="tag">天然草本</text>
        <text class="tag">健康睡眠</text>
        <text class="tag">引气归元</text>
      </view>
    </view>

    <!-- 进入主页按钮 - 为老年用户提供清晰的导航指引 -->
    <view class="home-navigation">
      <view class="nav-tip">
        <text class="nav-tip-icon">👉</text>
        <text class="nav-tip-text">想了解更多产品信息？</text>
      </view>
      <button class="home-button" @click="goToHome">
        进入主页查看详情
      </button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      promoter_id: null,
      shopAppId: "wx64874b77c972fb53", // 微信小店官方AppID
      coupon_stock_id: '149080833', // 优惠券id
      // 视频列表
      videoList: [
        { token: 'token/AWFb30aKR' },
        { token: 'token/AEdtg9M1B' },
        { token: 'token/A12kKz8FD' }
      ]
    };
  },
  onLoad(options) {
    // 在页面加载时获取分享链接中的 promoter_id
    if (options.promoter_id) {
      this.promoter_id = options.promoter_id;
      console.log('推荐人ID:', this.promoter_id);
      // 将推荐人ID存入缓存，待用户登录后进行关联
      uni.setStorageSync('promoter_id', this.promoter_id);
    }
  },
  methods: {
    // 打开优惠券详情页
    openCouponDetail() {
      wx.openStoreCouponDetail({
        couponId: this.coupon_stock_id,
        shopAppid: this.shopAppId,
        success(res) {
          console.log('成功打开优惠券详情页', res)
        },
        fail(err) {
          console.error('打开优惠券详情页失败', err);
          uni.showToast({ title: `跳转失败: ${err.errMsg}`, icon: 'none' });
        }
      });
    },

    // 跳转到主页 - 使用 switchTab 跳转到 tabBar 页面
    goToHome() {
      uni.switchTab({
        url: '/pages/index/index',
        success() {
          console.log('成功跳转到主页');
        },
        fail(err) {
          console.error('跳转主页失败', err);
          uni.showToast({
            title: '跳转失败，请稍后重试',
            icon: 'none'
          });
        }
      });
    },

    // 视频加载错误处理
    onVideoError(e) {
      console.error('========== 视频号视频加载失败 ==========');
      console.error('错误详情:', JSON.stringify(e, null, 2));
      console.error('错误类型:', e.type);
      console.error('错误信息:', e.detail);
      console.error('错误代码:', e.errCode);
      console.error('错误消息:', e.errMsg);
      console.error('========================================');

      // 显示错误提示
      uni.showToast({
        title: '视频加载失败，请检查配置',
        icon: 'none',
        duration: 3000
      });
    }
  },
};
</script>

<style>
.landing-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60rpx 40rpx;
  background: linear-gradient(180deg, #f8fdf8 0%, #ffffff 100%);
  min-height: 100vh;
  position: relative;
}

/* 背景纹理层 - 铺满整个页面 */
.page-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
}

.page-bg image {
  width: 100%;
  height: 100%;
  /* 使用混合模式增强纹理效果 */
  mix-blend-mode: multiply;
  opacity: 0.08;
}

/* 顶部标题 */
.page-header {
  text-align: center;
  margin-bottom: 50rpx;
  width: 100%;
  position: relative;
  z-index: 2;
}

.header-subtitle {
  display: block;
  font-size: 26rpx;
  color: #666666;
  margin-bottom: 16rpx;
  letter-spacing: 1rpx;
  /* 添加微妙的文字阴影 */
  text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
}

.header-title {
  display: block;
  font-size: 56rpx;
  font-weight: bold;
  color: #2d5a3d;
  letter-spacing: 4rpx;
  /* 添加文字阴影增强立体感 */
  text-shadow: 0 2rpx 8rpx rgba(74, 124, 89, 0.2);
}

/* 红包卡片 */
.coupon-card {
  width: 100%;
  background: linear-gradient(135deg, #FFF8E1 0%, #FFECB3 100%);
  border-radius: 20rpx;
  padding: 40rpx 30rpx;
  margin-bottom: 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(255, 193, 7, 0.15);
  position: relative;
  z-index: 2;
  overflow: hidden;
}

.coupon-card::before {
  content: '';
  position: absolute;
  top: -50rpx;
  right: -50rpx;
  width: 200rpx;
  height: 200rpx;
  background: radial-gradient(circle, rgba(255, 193, 7, 0.1) 0%, transparent 70%);
  border-radius: 50%;
}

.coupon-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8rpx;
  margin-bottom: 20rpx;
}

.badge-icon {
  font-size: 28rpx;
}

.badge-text {
  font-size: 24rpx;
  color: #F57C00;
  font-weight: 500;
}

.badge-dot {
  font-size: 24rpx;
  color: #F57C00;
  margin: 0 4rpx;
}

.coupon-amount {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8rpx;
}

.amount-number {
  font-size: 72rpx;
  font-weight: bold;
  color: #F57C00;
  line-height: 1;
}

.amount-label {
  font-size: 32rpx;
  color: #F57C00;
  font-weight: 600;
}

/* 领取按钮容器 - 用于承载按钮和动效 */
.claim-button-wrapper {
  width: 100%;
  position: relative;
  z-index: 2;
  margin-bottom: 50rpx;
}

/* 领取按钮 - 添加多重动画效果 */
.claim-button {
  background: linear-gradient(135deg, #4a7c59 0%, #5a8a4a 100%);
  color: white;
  font-size: 32rpx;
  font-weight: bold;
  border-radius: 50rpx;
  padding: 28rpx 0;
  width: 100%;
  text-align: center;
  box-shadow: 0 8rpx 24rpx rgba(74, 124, 89, 0.3);
  border: none;
  position: relative;
  z-index: 2;
  overflow: visible;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12rpx;
  /* 按钮缩放动画 - 持续吸引注意力 */
  animation: buttonPulse 2s ease-in-out infinite;
}

.claim-button::after {
  border: none;
}

/* 按钮文字 */
.button-text {
  position: relative;
  z-index: 1;
}

/* 按钮图标 - 添加摇摆动画 */
.button-icon {
  font-size: 32rpx;
  display: inline-block;
  animation: iconShake 1s ease-in-out infinite;
}

/* 呼吸光晕效果 - 在按钮周围产生光晕 */
.button-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #4a7c59 0%, #5a8a4a 100%);
  border-radius: 50rpx;
  z-index: 1;
  opacity: 0.6;
  /* 光晕呼吸动画 */
  animation: glowPulse 2s ease-in-out infinite;
}

/* 按钮按下效果 - 提供即时反馈 */
.claim-button:active {
  transform: scale(0.96);
  box-shadow: 0 4rpx 16rpx rgba(74, 124, 89, 0.4);
}

/* 按钮脉冲动画 - 轻微缩放吸引注意 */
@keyframes buttonPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
}

/* 光晕呼吸动画 - 扩散效果 */
@keyframes glowPulse {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.6;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.08);
    opacity: 0.3;
  }
}

/* 图标摇摆动画 - 增加趣味性 */
@keyframes iconShake {
  0%, 100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-15deg);
  }
  75% {
    transform: rotate(15deg);
  }
}

/* 视频区域 */
.video-section {
  width: 100%;
  margin-bottom: 40rpx;
  position: relative;
  z-index: 2;
}

.video-tip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8rpx;
  padding: 16rpx;
  margin-bottom: 20rpx;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12rpx;
  box-shadow: 0 4rpx 12rpx rgba(102, 126, 234, 0.3);
}

.tip-icon {
  font-size: 28rpx;
}

.tip-text {
  font-size: 26rpx;
  color: #ffffff;
  font-weight: 600;
}

.tip-sub {
  font-size: 22rpx;
  color: rgba(255, 255, 255, 0.8);
  margin-left: 8rpx;
}

/* 视频轮播 */
.video-swiper-container {
  width: 100%;
  border-radius: 20rpx;
  overflow: hidden;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.1);
}

.video-swiper {
  width: 100%;
  height: 450rpx;
}

.video-item {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
}

.product-video {
  width: 100%;
  height: 100%;
}

/* 产品信息 */
.product-info {
  width: 100%;
  text-align: center;
  padding: 30rpx;
  background: white;
  border-radius: 20rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  margin-bottom: 40rpx;
  position: relative;
  z-index: 2;
}

.product-name {
  font-size: 34rpx;
  font-weight: bold;
  color: #333333;
  margin-bottom: 16rpx;
  display: block;
  letter-spacing: 2rpx;
}

.product-desc {
  font-size: 26rpx;
  color: #666666;
  line-height: 1.8;
  margin-bottom: 24rpx;
  display: block;
}

.product-features {
  display: flex;
  justify-content: center;
  gap: 16rpx;
  flex-wrap: wrap;
}

.feature-tag {
  background: linear-gradient(135deg, #4a7c59 0%, #5a8a4a 100%);
  color: white;
  padding: 10rpx 20rpx;
  border-radius: 30rpx;
  font-size: 24rpx;
  font-weight: 500;
  box-shadow: 0 2rpx 8rpx rgba(74, 124, 89, 0.2);
}

.philosophy-section {
  background: linear-gradient(135deg, #4a7c59 0%, #5a6d33 100%);
  border-radius: 20rpx;
  padding: 40rpx;
  width: 100%;
  color: white;
  text-align: center;
  box-shadow: 0 12rpx 32rpx rgba(74, 124, 89, 0.3);
  position: relative;
  z-index: 2;
}

.philosophy-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 25rpx;
}

.philosophy-title {
  font-size: 32rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
  display: block;
}

.philosophy-text {
  font-size: 26rpx;
  line-height: 1.8;
  margin-bottom: 25rpx;
  opacity: 0.95;
}

.philosophy-tags {
  display: flex;
  justify-content: center;
  gap: 15rpx;
  flex-wrap: wrap;
}

.tag {
  background-color: rgba(255, 255, 255, 0.2);
  padding: 8rpx 16rpx;
  border-radius: 20rpx;
  font-size: 22rpx;
  backdrop-filter: blur(10rpx);
}

/* 主页导航区域 - 为老年用户优化的导航指引 */
.home-navigation {
  width: 100%;
  margin-top: 50rpx;
  padding: 40rpx 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24rpx;
  position: relative;
  z-index: 2;
}

.nav-tip {
  display: flex;
  align-items: center;
  gap: 12rpx;
  padding: 16rpx 24rpx;
  background: #f5f5f5;
  border-radius: 30rpx;
}

.nav-tip-icon {
  font-size: 28rpx;
}

.nav-tip-text {
  font-size: 26rpx;
  color: #666666;
  font-weight: 500;
}

/* 主页按钮 - 轮廓样式，与主按钮区分 */
.home-button {
  background: white;
  color: #4a7c59;
  font-size: 30rpx;
  font-weight: bold;
  border-radius: 50rpx;
  padding: 26rpx 0;
  width: 100%;
  text-align: center;
  border: 3rpx solid #4a7c59;
  box-shadow: 0 4rpx 16rpx rgba(74, 124, 89, 0.15);
  transition: all 0.3s ease;
}

.home-button::after {
  border: none;
}

/* 按钮按下效果 - 提供清晰的视觉反馈 */
.home-button:active {
  background: #f0f7f3;
  transform: scale(0.98);
}
</style>
